/*
* jlb
*/
package com.jlb.user.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.user.entity.User;
import com.jlb.user.entity.UserOre;
import com.jlb.user.service.UserOreSV;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 矿石 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/userOre")
@Slf4j
@Api(value = "矿石控制器", description = "矿石控制器")
public class UserOreCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private UserOreSV userOreSV;
    @Resource
    private UserSV userSV;

    /**
     * 查询UserOre一个详情信息
     *
     * @param id
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserOre一个详情信息", notes = "查询UserOre一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String userCode) {
        if (id == null) {
            return null;
        }
        if (userCode == null) {
            return null;
        }
        UserOre userOre = userOreSV.load(id, userCode);
        log.info(JSON.toJSONString(userOre));
        return BeanRet.create(true, "查询成功", userOre);
    }


    /**
     * 根据条件id查询UserOre一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserOre一个详情信息", notes = "查询UserOre一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        UserOre userOre = userOreSV.loadById(id);
        log.info(JSON.toJSONString(userOre));
        return BeanRet.create(true, "查询成功", userOre);
    }

    /**
     * 根据条件userCode查询UserOre一个详情信息
     *
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserOre一个详情信息", notes = "查询UserOre一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/userCode/{userCode}")
    @ResponseBody
    public BeanRet loadByUserCode(@PathVariable java.lang.String userCode) {
        if (userCode == null) {
            return null;
        }
        UserOre userOre = userOreSV.loadByUserCode(userCode);
        log.info(JSON.toJSONString(userOre));
        return BeanRet.create(true, "查询成功", userOre);
    }


    /**
     * 查询UserOre信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserOre信息集合", notes = "查询UserOre信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "query"),
            @ApiImplicitParam(name = "state", value = "激活 Active，停止 Stop", paramType = "query"),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(String account, @ApiIgnore UserOre userOre, Integer curPage, Integer pageSize) {
        Page<UserOre> page = new Page<>(pageSize, curPage);
        if (account != null) {
            User user = userSV.loadByAccount(account);
            if (user == null) {
                return BeanRet.create(true, "查询成功", page);
            }
            userOre.setUserCode(user.getCode());
        }
        List<UserOre> userOres = userOreSV.list(userOre, page.genRowStart(), page.getPageSize());
        page.setVoList(userOres);
        int total = userOreSV.count(userOre);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询UserOre信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserOre信息集合", notes = "查询UserOre信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String userCode, Integer curPage, Integer pageSize) {
        Page<UserOre> page = new Page<UserOre>(pageSize, curPage);
        List<UserOre> userOres = userOreSV.list(id, userCode, page.genRowStart(), page.getPageSize());
        page.setVoList(userOres);
        int total = userOreSV.count(id, userCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计UserOre信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计UserOre信息数量根据主键", notes = " 统计UserOre信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String userCode) {
        return userOreSV.count(id, userCode);
    }

    /**
     * 统计UserOre信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计UserOre信息数量", notes = "统计UserOre信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石总量", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore UserOre userOre) {
        if (userOre == null) {
            return userOreSV.count(new HashMap());
        } else {
            return userOreSV.count(userOre);
        }
    }

    /**
     * 用户动态复投
     *
     * @return BeanRet
     */
 /*   @ApiOperation(value = "用户动态复投", notes = "用户动态复投")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "payType", value = "支付方式", paramType = "query"),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query")
    })
    @PostMapping("/recast")
    @ResponseBody
    public BeanRet recast(String account, String payType, String pinPassword) {
        if (StringUtils.isBlank(account) || StringUtils.isBlank(payType)) {
            return BeanRet.create();
        }
        userOreSV.recast(account, payType, pinPassword);
        return BeanRet.create(true, "复投成功");
    }
*/

    /**
     * 创建UserOre
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建UserOre", notes = "创建UserOre")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ore", value = "矿石总量", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore UserOre userOre) {
        userOreSV.save(userOre);
        return BeanRet.create(true, "创建成功", userOre);
    }


    /**
     * 修改UserOre
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改UserOre", notes = "修改UserOre")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石总量", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore UserOre userOre) {
        userOreSV.modify(userOre);
        return BeanRet.create(true, "修改成功", userOre);
    }

    /**
     * 删除UserOre
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除UserOre", notes = "删除UserOre")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String userCode) {
        userOreSV.delete(id, userCode);
        return BeanRet.create(true, "删除UserOre成功");
    }

}
